#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include "network_handler.h"

/*
	Calculate size of data in net_packge 

		1. sizeof(struct) - sizeof(int) - sizeof(char)
*/

int SendTextMessage(int tar_socket, char *msg)
{
	
}

int SendData(int tar_socket, char *data)
{
	int n = write(tar_socket, data, sizeof(*data));
	if (n  < 0)
		return 0;
	else
		return 1;
}

int RecieveMessage(int tar_socket, char *tmpbuffer)
{
	int n = 0;
	
	n = read(tar_socket, tmpbuffer, sizeof(tmpbuffer));

	if (n<=0)
		return 0;
	else
		return 1;
}

int SendPackage(int tar_socket, struct net_package *package)
{
	// First we send our status
	SendData(tar_socket ,(char *) package->status);
	
	// Then we send the size
	SendData(tar_socket, (char *) package->size);
	
	// Here comes the data
	SendData(tar_socket, (char *) package->buffer);
}
